<template>
    <div>
        <base-form :fields="fields" v-model="form" ref="formRef" :readonly="true" labelWidth="140px" :showPlaceholder="false">
        </base-form>
        <div class="text-center">
            <el-button @click="close">关闭</el-button>
        </div>
    </div>
</template>
<script setup>
    import https from '@/utils/https'
    import { onMounted } from 'vue'
    import * as _ from 'lodash'

    const emits = defineEmits(["close"])
    const props = defineProps({
        item: Object,
    })
    const fields = [
        { label: '分类', prop: 'categoryName' },
        { label: '关联模型', prop: 'modelName' },
        { label: '报警标题', prop: 'title' },
        { label: '报警内容', prop: 'content', type: 'textarea' },
        { label: '报警等级', prop: 'level' },
        { label: '报警次数', prop: 'alarmCount' },
        { label: '首次上报时间', prop: 'createTime' },
        { label: '最后上报时间', prop: 'lastUpTime' },
        { label: '是否关闭', prop: 'closed', type: 'switch' },
        { label: '关闭时间', prop: 'closeTime' },
        { label: '备注', prop: 'remark', type: 'textarea' },

    ]

    const form = ref({
        level: 3,
        autoClose: true,
        title: '设备(${deviceCode})于(${alarmTime})产生***报警'
    })
    const formRef = ref()
    const editing = ref(false)

    onMounted(() => {
        if (props.item) {
            https.get('/manager/alarm/detail/' + props.item.id).then(resp => {
                form.value = resp
                editing.value = false
            })
        } else {
            editing.value = true
            if (props.category) {
                form.value.categoryId = props.category.id
            }
        }
    })

    function loadCategory() {
        return https.get('/manager/alarm-category/tree')
    }

    function loadModels() {
        return https.post('/manager/device-model/query')
    }

    function close() {
        emits('close')
    }
</script>

<style lang='scss' scoped></style>